﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Interface_Tier;
using Transfer_Object_Tier;
using System.Configuration;

namespace eSolution_HRMSS.UserControls
{
    public partial class UC_CongViec : DevExpress.XtraEditors.XtraUserControl
    {
        public UC_CongViec()
        {
            InitializeComponent();
        }

        IDIC_JOBData _ijob;

        eSolution_HRMSS.HRMSS_Ultil util = new HRMSS_Ultil();

        private void UC_BangCap_Load(object sender, EventArgs e)
        {
            //dang ky de ket noi ung dung toi server do windows service quan ly
            _ijob = (IDIC_JOBData)Activator.GetObject(typeof(IDIC_JOBData), util.Chuoicongviec);
            
            //hoi nay con thieu mot buoc la goi ham load_ds() trong su kien formload
            //do la ly do ma no ko co du lieu do len luoi. gi chay lai
            load_ds();
        }
        
        //tao ham load danh sach bang cap len lưới
        private void load_ds()
        {
            grdDSbangcap.DataSource = _ijob.DIC_JOB_GetList().Tables[0];
            //nen de them la lay datatable nao, neu khong no se bi nhu hoi nay
        }

        private void btthemmoi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            eSolution_HRMSS.Winforms.DanhMuc.FR_CongViec congviec = new Winforms.DanhMuc.FR_CongViec(false);
            congviec.truyentinhieu = new Winforms.DanhMuc.FR_CongViec.updatelist(load_ds);
            congviec.ShowDialog(this);
        }
        private void btsua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string ma=dsbangcap.GetFocusedDataRow()[0].ToString();
            eSolution_HRMSS.Winforms.DanhMuc.FR_CongViec congviec = new Winforms.DanhMuc.FR_CongViec(true, ma);
            congviec.truyentinhieu = new Winforms.DanhMuc.FR_CongViec.updatelist(load_ds);
            congviec.ShowDialog(this);
        }
        private void btnaplai_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            load_ds();
        }

        private void btxuat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            saveFileDialog1.Filter = "Excel File|*.xls";
            saveFileDialog1.Title = "Xuất danh sách ra file MS Excel";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (saveFileDialog1.FileName.Length > 0)
                {
                    grdDSbangcap.ExportToXls(saveFileDialog1.FileName.ToString());
                }
            }
        }

        private void btdong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            
        }

        private void dsbangcap_DoubleClick(object sender, EventArgs e)
        {
            string ma = dsbangcap.GetFocusedDataRow()[0].ToString();
            eSolution_HRMSS.Winforms.DanhMuc.FR_CongViec congviec = new Winforms.DanhMuc.FR_CongViec(true, ma);
            congviec.truyentinhieu = new Winforms.DanhMuc.FR_CongViec.updatelist(load_ds);
            congviec.ShowDialog(this);
        }

        private void btxoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (MessageBox.Show(util.Xacnhanxoa, "Xác nhận thông tin", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                foreach (int selectedindex in dsbangcap.GetSelectedRows())
                {
                    string ma = ((DataRowView)dsbangcap.GetRow(selectedindex))[0].ToString();

                    if (_ijob.DIC_JOB_Delete(ma) < 0)
                    {
                        MessageBox.Show(util.Loithaotac);
                    }
                }
                load_ds();
            }
        }

        private void btin_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            

        }
    }
}
